package org.jwxa.jwxa4j.parser;

import java.util.Iterator;

import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
import org.jwxa.jwxa4j.nodes.WXElement;
import org.jwxa.jwxa4j.nodes.WXNode;

/**
 * 构建Element节点
 * @author janjan, xujian_jason@163.com
 *
 */
public class ElementBuilder implements TreeBuilder {

	@Override
	public WXNode build(Object object) {
		if(object == null) {
			return null;
		}
		// 元素节点
    	Element childElement = (Element) object;
    	// copy属性
    	Attributes attributes = childElement.attributes();
    	WXElement wxChildNode = new WXElement(childElement.tagName());
    	for (Iterator<Attribute> iterator = attributes.iterator(); 
    			iterator.hasNext();) {
    		Attribute attr = iterator.next();
    		wxChildNode.attr(attr.getKey(), attr.getValue());
		}
    	return wxChildNode;
	}

}
